package com.doubao.wechat.controller;

import com.doubao.common.result.Result;
import com.doubao.wechat.feign.UserFeignClient;
import com.doubao.wechat.feign.dto.UserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试控制器
 */
@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {

    @Autowired
    private UserFeignClient userFeignClient;

    /**
     * 测试用户服务Feign客户端
     */
    @GetMapping("/user/{userId}")
    public Result<UserDTO> testUserFeign(@PathVariable Long userId) {
        log.info("测试获取用户信息: userId={}", userId);
        Result<UserDTO> result = userFeignClient.getUserById(userId);
        log.info("用户信息获取结果: {}", result);
        return result;
    }

    /**
     * 健康检查
     */
    @GetMapping("/health")
    public Result<String> health() {
        return Result.success("服务正常运行");
    }
}